/*
 * net_addressing.c
 *
 *  Created on: 2023年7月22日
 *      Author: mcealt_DS
 */
#include "net_addressing.h"
#include "device.h"
#include "util.h"
#include "app_log.h"
uint32_t readThisPanId(void)
{
    uint8_t buff[3];
    uint32_t this_panId = 0;
    if (getThisParam(ENpbyPanId, buff) == 0)
    {
        this_panId = l_get_be24(buff);
#ifdef CONFIG_LOG_NET_ADDRESSING
        DS_app_log_debug("pId:0x%06X\r\n", this_panId);
#endif
    }
    else
    {
        DS_app_log_error("no pId\r\n");
        this_panId = PANID_MAX;
    }
    return this_panId;
}

// 判断是否与本设备的panid一样
bool net_addressing_check_panId(uint32_t panId)
{
//    uint8_t buff[3];
    uint32_t this_panId = readThisPanId();

    if (this_panId > PANID_MAX)
    {
        return false;
    }
    if (panId == this_panId)
        return true;
    else
        return false;
}

// 读取本设备的systemid
uint32_t readThisSystemId(void)
{
    uint8_t buff[3];
    uint32_t this_systemid = 0;
    if (getThisParam(ENpbySystemID, buff) == 0)
    {
        this_systemid = l_get_be24(buff);
#ifdef CONFIG_LOG_NET_ADDRESSING
        DS_app_log_debug("sysId:0x%06X\r\n", this_systemid);
#endif
    }
    else
    {
        DS_app_log_error("no sysId\r\n");
        this_systemid = PANID_MAX;
    }
    return this_systemid;
}

// 判断是否与本设备的sysid一样
bool net_addressing_check_sysId(uint32_t systemid)
{
//    uint8_t buff[3];
    uint32_t this_systemid = readThisSystemId();

    if (this_systemid > SYSTEMID_MAX)
    {
        return false;
    }
    if (systemid == this_systemid)
        return true;
    else
        return false;
}
